package com.asset.dispoal.business.mediation.service.common;

import com.asset.dispoal.business.mediation.domain.db.mapper.ReduceOperateMapper;
import com.asset.dispoal.business.mediation.dto.MediationRequest;
import com.asset.dispoal.business.mediation.dto.MediationResponse;
import com.asset.dispoal.commom.page.PagingQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * @description:
 * @author: yf
 * @date: 2022-08-23 08:29:24
 */
@Component
public class QueryBorrowerInfoCommand implements BaseCommand<MediationRequest, Result<PageVO<MediationResponse>>> {
    @Autowired
    private ReduceOperateMapper reduceOperateMapper;

    @Override
    public Result<PageVO<MediationResponse>> execute(MediationRequest mediationRequest) {
        int count = reduceOperateMapper.queryCount(mediationRequest);
        Page<MediationRequest> page = PagingQuery.getPage(count, mediationRequest);
        PageVO<MediationResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);

        if (page != null) {
            List<MediationResponse> result = reduceOperateMapper.queryPage(page);
            pageVO.setResult(result);
        }
        return Result.ok(pageVO);

    }
}
